<?php

namespace App\Models\Common\EntityData\Channel;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * Class Sp
 * @package App\Models\Common\EntityData\Channel
 * @version August 1, 2017, 4:31 pm UTC
 */
class Sp extends Model
{
    use SoftDeletes;

    public $table = 'sps';

    protected $dates = ['deleted_at'];

    public $fillable = [
        'name',
        'title',
        'subtitle',
        'short_desc',
        'sp_no',
        'sp_key',
        'sgroup_id',
        'logo',
        'description',
        'created_at',
        'updated_at',
    ];

    /**
     * The attributes that should be casted to native types.
     *
     * @var array
     */
    protected $casts = [
        'name'        => 'string',
        'title'       => 'string',
        'subtitle'    => 'string',
        'sp_no'       => 'string',
        'sp_key'      => 'string',
        'short_desc'  => 'string',
        'logo'        => 'string',
        'description' => 'string',
    ];

    /**
     * Validation rules
     *
     * @var array
     */
    public static $rules = [
        'name'       => 'required|max:100',
        'title'      => 'max:100',
        'subtitle'   => 'max:100',
        'short_desc' => 'required|max:100',
    ];

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     **/
    public function sgroup()
    {
        return $this->hasOne(\App\Models\Common\EntityData\Channel\Sgroup::class, 'id', 'sgroup_id');
    }


    /**
     * 获得SP的所有管理员。
     */
    public function adminUsers()
    {
        return $this->hasMany('App\Models\Admin\AdminUser','sp_id');
    }

}
